import { Router } from 'vue-router'
import { Storage } from '../../utils/localStorage'
import { showToast } from 'vant'

const storage = new Storage()
export default (router: Router) => {
   router.beforeEach((to, from, next) => {
      const item = storage.getStorage('token')
      if (to.meta?.auth) {
         if (item?.token) {
            next()
         } else {
            showToast('请先登录')
            next({ name: 'login' })
         }
      } else {
         next()
      }
   })
}
